/*
Copyright (c) 2013, Le Tallec Jean-Francois

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "fortuneFrontend.h"

fortuneFrontend::fortuneFrontend(int argc, char ** argv){
	// Wrap everything in a try block.  Do this every time, 
	// because exceptions will be thrown for problems.
	try {  
	// Define the command line object, and insert a message
	// that describes the program. The "Command description message" 
	// is printed last in the help text. The second argument is the 
	// delimiter (usually space) and the last one is the version number. 
	// The CmdLine object parses the argv array based on the Arg objects
	// that it contains. 
	TCLAP::CmdLine cmd("Fortune's command line description", ' ', "1.0");
	TCLAP::ValueArg<std::string> dbnameArg("d","database","Database file name",true,"","string");
	cmd.add(dbnameArg);
	TCLAP::SwitchArg addQuotesArg("q","quote","Add a new quotes to the database",false);
	cmd.add(addQuotesArg);
	TCLAP::SwitchArg listAuthorsArg("l","listauth","Display the authors' list of the database",false);
	cmd.add(listAuthorsArg);
	TCLAP::SwitchArg randomQuotesArg("r","randquote","Display a random quote",false);
	cmd.add(randomQuotesArg);
	TCLAP::SwitchArg authorRandomQuotesArg("a","authrandquote","Display a specif author's random quote",false);
	cmd.add(authorRandomQuotesArg);
	TCLAP::SwitchArg newDatabaseArg("n","newdb","Create a new database",false);
	cmd.add(newDatabaseArg);
	
	// Parse the argv array.
	cmd.parse( argc, argv );
	//assign parameter to variables
	dbName= dbnameArg.getValue();
	addQuotes= addQuotesArg.getValue();
	listAuthors= listAuthorsArg.getValue();
	randomQuotes= randomQuotesArg.getValue();
	authorRandomQuotes= authorRandomQuotesArg.getValue();
	newDatabase= newDatabaseArg.getValue();

	} catch (TCLAP::ArgException &e)  // catch any exceptions
	{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; }
}

fortuneFrontend::~fortuneFrontend(){}

std::string fortuneFrontend::getDbName(){return dbName;}
bool fortuneFrontend::getAddQuotes(){return addQuotes;}
bool fortuneFrontend::getListAuthors(){return listAuthors;}
bool fortuneFrontend::getRandomQuotes(){return randomQuotes;}
bool fortuneFrontend::getAuthorRandomQuotes(){return authorRandomQuotes;}
bool fortuneFrontend::getNewDatabase(){return newDatabase;}


